#include "EngineScript.h"
#include "T_Engine.h"
#include "clazz.h"

int engine_GetInstance(lua_State *L){
	T_Engine *engine = T_Engine::pEngine;
	ModuleInstance(L,engine,"Engine");
	return 1;
}

int engine_GetInterval(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	lua_pushinteger(L,engine->GetInterval());
	return 1;
}
int engine_SetFrame(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	int interval = (int)luaL_checkinteger(L,2);
	engine->SetFrame(interval);
	return 0;
}
int engine_GetSleep(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	lua_pushboolean(L,engine->GetSleep());
	return 1;
}
int engine_SetSleep(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	engine->SetSleep(lua_toboolean(L,2));
	return 0;
}
int engine_SetFullScreen(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	engine->SetFullScreen(lua_toboolean(L,2));
	return 0;
}
int engine_CheckKey(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	WPARAM wParam = (WPARAM)luaL_checkinteger(L,2);
	lua_pushboolean(L,engine->CheckKey(wParam));
	return 1;
}
int engine_GetSize(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	ModuleInstance(L,new Gdiplus::SizeF(engine->GetSize()),"Size",true);
	return 1;
}
int engine_getCurScene(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	ModuleInstance(L,engine->getCurScene(),"Scene");
	return 1;
}
int engine_runScene(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	T_Scene *scene = (T_Scene *)ModuleCheck(L,2,"Scene");
	engine->runScene(scene);
	return 0;
}
int engine_resumeScene(lua_State *L){
	T_Engine *engine = (T_Engine *)ModuleCheck(L,1,"Engine");
	engine->resumeScene();
	return 0;
}

int lua_openengine(lua_State *L){
	BeginModule(L,"Engine");
	InitModule(L,0,0);
	StaticFunction(L,"getInstance",engine_GetInstance);
	NormalFunction(L,"GetInterval",engine_GetInterval);
	NormalFunction(L,"SetFrame",engine_SetFrame);
	NormalFunction(L,"GetSleep",engine_GetSleep);
	NormalFunction(L,"SetSleep",engine_SetSleep);
	NormalFunction(L,"SetFullScreen",engine_SetFullScreen);
	NormalFunction(L,"CheckKey",engine_CheckKey);
	NormalFunction(L,"GetSize",engine_GetSize);
	NormalFunction(L,"getCurScene",engine_getCurScene);
	NormalFunction(L,"runScene",engine_runScene);
	NormalFunction(L,"resumeScene",engine_resumeScene);
	EndModule(L);
	return 0;
}

int lua_closeengine(lua_State *L){
	lua_pushnil(L);
	lua_setglobal(L,"Engine");
	return 0;
}